package bTree.LeetCode;

public class 比较版本号 {
    public int compareVersion(String version1, String version2) {
        String[] split1 = version1.split("\\.");
        String[] split2 = version2.split("\\.");
        int maxLength = Math.max(split1.length, split2.length);
        for (int i = 0; i < maxLength; i++) {
            int v1 = i < split1.length ? Integer.parseInt(split1[i]) : 0;
            int v2 = i < split2.length ? Integer.parseInt(split1[i]) : 0;
            if (v1 > v2) {
                return 1;
            }
            if (v1 < v2) {
                return -1;
            }
        }
        return 0;
    }
}